package cn.donting.jme.edit.ui.inspector;

import cn.donting.jme.edit.attribute.ValueChangeListener;
import javafx.scene.control.CheckBox;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

public class InspectorUI {

    private Pane uiNode;
    public final String title;
    public final ImageView icon;
    private final List<ValueChangeListener<Boolean>> enableChangeListeners = new ArrayList<>();
    private final List<ValueChangeListener<Boolean>> removeChangeListeners = new ArrayList<>();

    /**
     * 是否显示 启用勾选项
     */
    @Setter
    @Getter
    private boolean showEnable = false;

    /**
     * 是否可以移除
     */
    @Setter
    @Getter
    private boolean remove = false;

    public final CheckBox checkBox = new CheckBox();

    public InspectorUI(Pane uiNode, String title, ImageView icon) {
        this.uiNode = uiNode;
        this.title = title;
        this.icon = icon;
        if (icon != null) {
            icon.setFitHeight(16);
            icon.setFitWidth(16);
        }
        checkBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
            for (ValueChangeListener<Boolean> booleanValueChangeListener : enableChangeListeners) {
                booleanValueChangeListener.valueChange(oldValue,newValue);
            }
        });



    }

    public Pane getUiNode() {
        return uiNode;
    }

    public void addEnableListener(ValueChangeListener<Boolean> attributeListener) {
        enableChangeListeners.add(attributeListener);
    }

    public boolean removeEnableListener(ValueChangeListener<Boolean> attributeListener) {
        return enableChangeListeners.remove(attributeListener);
    }

    public void addRemoveChangeListenersListener(ValueChangeListener<Boolean> attributeListener) {
        removeChangeListeners.add(attributeListener);
    }

    public boolean removeRemoveListener(ValueChangeListener<Boolean> attributeListener) {
        return removeChangeListeners.remove(attributeListener);
    }
}
